<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>商家列表</title>
		<link rel="stylesheet" href="__OEM__/css/iconfont.css" />
		<link rel="stylesheet" href="__OEM__/css/css.css" />
	</head>
<style>
	.pagination{
		margin-top: 10px;
		float: right;
	}
	.chax_conbox {
    margin-top: 0px;
	}
	.huizcx_top {
    padding: 0 0 0;
    }
	.shangj_btn{background-color: #FF7831; border-radius: 3px;color: #fff;padding:3px 10px;}

</style>
	<body>
		{include file="public/header" /}
		<div class="index_conbox">
			<div class="index_content clearfix">
				{include file="public/lefter" /}
				<div class="right">
					<!--右侧内容-->
					<div class="rigtop">
						<span class="title">商家列表</span>
					</div>
					<div class="indrig_con" style="position: relative;">
						{if $Think.session.user_level==3}
						<div class="zizh_btnbox" style="top: -58px;right:30px">
							<button class="zizh_btn" type="button"><i class="iconfont icon-jia"></i>创建商户</button>
						</div>
						{/if}
						<div class="zizh_conbox" style="padding-top: 20px;">
							<!--选项卡内容开始-->
							<div class="huizcx_top">
								<!-- <div class="chax_rowbox2 clearfix"> -->
									<form id="my_form" action="{:url('oem/accounts/agent')}" method="post">
										<div class="shxx_row chax_row clearfix">
											<div class="left">店铺名称：</div>
											<div class="right clearfix">
												<input type="text" name="agent_name" id="agent_name" value="{$agent_name}" placeholder="店铺名称" class="chax_input" />
											</div>
				
											<div class="left">手机号码：</div>
											<div class="right clearfix">
												<input type="text" name="mobile" id="mobile" value="{$mobile}" placeholder="手机号码" class="chax_input" />
											</div>
										
										{if $Think.session.user_level==1 || $Think.session.user_level==4}
												<div class="left">区域运营商ID：</div>
												<div class="right clearfix">
													<input type="text" name="ch_city" id="ch_city" value="{$ch_city}" placeholder="区域运营商ID" class="chax_input" />
												</div>
										{/if}
										{if $Think.session.user_level==2}
												<div class="left" >区域运营商：</div>
									            <div class="right clearfix">
													<div id="htselect" style="width: 152px;min-width: 152px;">	
													<select name="ch_city" id="ch_city">
														<option value="">全部</option>
														{volist name="area" id="city"}
															<option value="{$city.id}" {if $city.id==$ch_city}selected{/if}>{$city.user_name}</option>
														{/volist}
													</select>
													</div>
												</div>
										{/if}
											<div class="left">市场专员：</div>
											<div class="right clearfix">
												<input type="text" name="cm" id="cm" value="{$cm}" placeholder="手机号码" class="chax_input" />
											</div>
											<div class="left">排序：</div>
									            <div class="right clearfix">
													<div id="htselect" style="width: 152px;min-width: 152px;">	
													<select name="order" id="order">
														<option value="">全部</option>
															<option value="1" {if $order == 1}selected{/if}>鼓励金</option>
															<option value="2" {if $order == 2}selected{/if}>推广数</option>
													</select>
													</div>
											</div>
										{if $Think.session.user_level==1 || $Think.session.user_level==4}
										
												<div class="left" >市级代理商：</div>
									            <div class="right clearfix">
													<div id="htselect" style="width: 152px;min-width: 152px;">	
													<select name="operator" id="operator">
														<option value="">全部</option>
														{volist name="agency" id="vo"}
															<option value="{$vo.id}" {if $vo.id==$agency_id1}selected{/if}>{$vo.user_name}</option>
														{/volist}
													</select>
													</div>
												</div>
										{/if}
										{if $Think.session.user_level==1}
												<div class="left" >省级代理商：</div>
									            <div class="right clearfix">
													<div id="htselect" style="width: 152px;min-width: 152px;">	
													<select name="province" id="province">
														<option value="">全部</option>
														{volist name="province" id="str"}
															<option value="{$str.id}" {if $str.id==$agency_id}selected{/if}>{$str.user_name}</option>
														{/volist}
													</select>
													</div>
												</div>
										{/if}
											<button type="submit" class="htcxbtn">查询</button>
										</div>
									</form>
								<!-- </div>		 -->
								<div class="chax_conbox">
									<div class="chax_jiegbt clearfix">
										<div class="chax_jieg">总计：{$list->total();}家</div>
										<div class="chax_xzbtnbox">
											<a href="javascript:;" onclick="check()"><i class="iconfont icon-download"></i>商家下载</a>
										</div>
									</div>
									{if $Think.session.user_level==2 || $Think.session.user_level==1}
										<a href="javascript:;" class="shangj_btn" onclick="chuli(1)">显示</a>
										<a href="javascript:;" class="shangj_btn" onclick="chuli(2)">隐藏</a>
									{/if}
									<div class="chax_jiegnr">
										<table class="zizh_table1 zizh_table2">
											<thead>
												<tr style="text-align: center;">
													{if $Think.session.user_level==2 || $Think.session.user_level==1}
													<th style="width: 30px;">
														<input type="checkbox" onclick="check_all(this)" />
													</th>
													{/if}
													<th class="w_5">ID</th>
													<th class="w_10">商家名称<br />手机号码</th>
													<th class="w_5">抵扣比例</th>
													<th width="w_10">市场专员手机号</th>
													{if $Think.session.user_level==2}
														<th class="w_10">区域运营商</th>
													{/if}
													<!-- <th width="w_10">手机号码</th> -->
													<th class="w_5">余额</th>
													<th class="w_5">鼓励金</th>
													<th class="w_10">资质认证</th>
													<th width="w_5">推广数</th>
													<th width="w_5">归类</th>
													<th width="w_5">状态</th>
													<th width="w_10">创建时间</th>
													<th width="15%">操作</th>
												</tr>
											</thead>
											<tbody id="tbody">
												{volist name="list" id="vo" empty="$empty"}
												<tr style="text-align: center;">
													{if $Think.session.user_level==2 || $Think.session.user_level==1}
													<td><input type="checkbox" name="chk[]" value='{$vo.id}'> </td>
													{/if}
													<td>{$vo.id}</td>
													
													<td style="text-align: left;"><a class="iconfont icon-erweima"  href="javascript:;" onclick="fukuan('{$vo.id}')"></a>{$vo.agent_name}<br />{$vo.mobile}</td>
													<td>{$vo.ad_score}%</td>
													<td>{$vo.cm}</td>
													{if $Think.session.user_level==2}
														<td style="text-align: left;">{$vo.city_name}</td>
													{/if}
													<!-- <td>{$vo.mobile}</td> -->
													<td>
														<a href="javascript:;show_charge({$vo['id']})">
														<?php echo substr($vo['balance'],0,strlen($vo['balance'])-2)?>
														</a>
													</td>
													<td>
														<a href="javascript:;show_score({$vo['id']})">
															<?php echo substr($vo['score'],0,strlen($vo['score']))?>
														</a>
													</td>
													<td>{if $vo.is_state==1}<a href="{:url('index/qianyue_step',['agent_id'=>$vo.id])}">已签约</a>
														{elseif $vo.is_state==2}
														未签约
														{elseif $vo.is_state==3}
														<a href="{:url('index/qianyue_step',['agent_id'=>$vo.id])}">未通过</a>
														{/if}</td>
													<td>
														<a href="{:url('accounts/agents_tg',['id'=>$vo.id])}">
															{$vo.count?$vo.count : 0}
														</a>
													</td>
													<td>
															<?php if($vo['category_count']>0){ ?><a onclick="wanshan('{$vo.id}')" class="green">
																去优化
															</a><?php }else{ ?>
																<a onclick="wanshan('{$vo.id}')" class="gray">
																		未完善
																	</a>
																<?php } ?>
													</td>
													<td>
														{if $vo.status==1}
														正常
														{else/}
														冻结
														{/if}
													</td>
													<td>{$vo.add_time}</td>		
													
														<td style="text-align: center;">
															{if $Think.session.user_level==2 || $Think.session.user_level==1}
																{if $vo.status == 1}
																	<a href="javascript:;" onclick="caozuo('{$vo.id}','2')" class="gray">冻结</a>
																		{else/}
																	<a onclick="edit_agent('{$vo.id}')">编辑</a>
																	<a href="javascript:;" onclick="caozuo('{$vo.id}','1')" class="gray">激活</a>
																{/if}
															
																{if $vo.is_huilu == 1}
																	<a href="javascript:;" onclick="is_display('{$vo.id}','2')" class="green">不显示</a>
																{else}
																	<a href="javascript:;" onclick="is_display('{$vo.id}','1')" class="green">显示</a>
																{/if}
															{/if}
															<a href="javascript:;" onclick="setagent('{$vo.id}')" style="background-color:peru;">层级</a>
															
															{if $Think.session.user_level==3}
																<a href="javascript:;" onclick="qr_code('{$vo.id}')" style="background-color:slateblue;">绑定二维码{$vo.code_count}</a>
																{else}
																{if $vo.code_count}
																<a href="javascript:;" onclick="qr_code('{$vo.id}')" style="background-color:slateblue;">查看绑定{$vo.code_count}</a>
																{/if}
															{/if}
															<a href="javascript:;" onclick="agent_count('{$vo.id}','1')">统计</a>
														</td>
												</tr>
												{/volist}
										</table>
									</div>
									{$list->render()}
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>
		</div>
		{include file="public/footer" /}

	</body>
	<script>
		function check_all(obj){
			$ck=$(obj).prop("checked");
			$("tbody :checkbox, #all").prop("checked",$ck);
			
		}
		function chuli(status) {
			var chsub = $("input[name='chk[]']:checked").length;
			if (chsub > 0) {
				var lay=layer.confirm('确认操作?', {
				icon: 3,
				title: '提示'
				}, function(index) {
					layer.close(lay);
					var arr=new Array();
					$("input[name='chk[]']:checked").each(function(){
						var id=$(this).val();
						arr.push(id);
					})
					$.ajax({
							url:"{:url('accounts/chuli')}",
							data:{arr:arr,status:status},
							type:"post",
							success: function(data) {
								layer.msg(data.msg);
								if(data.code==200){
									window.location.reload();
								}
									
							}
					})
				});
			} else {
				layer.msg("请选择操作对象!");
				return ;
			}
		}
		$(".zizh_btn").click(function() {
			layer.open({
				type: 2,
				title: '添加商家',
				shadeClose: false,
				shade: 0.8,
				area: ['800px', '700px'],
				content: "{:url('accounts/add_agent')}"
			});
		})

		function qr_code(id) {
			var url ="agent_add_qr_code?agent_id="+id;
			layer.open({
			  type: 2,
			  title: '绑定的二维码',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['426px', '688px'],
			  content: [url]
			}); 
		}

		function fukuan(id) {
			var url ="fukuan?id="+id;
			layer.open({
			  type: 2,
			  title: '收款二维码',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['1800px', '900px'],
			  content: [url]
			}); 
		}

		function show_agent(id) {
			var url = 'show_agent?id=' + id;
			layer.open({
				type: 2,
				title: '商家详情',
				shadeClose: true,
				shade: 0.8,
				area: ['500px', '500px'],
				content: [url]
			});
		}

		function edit_agent(id) {
			var url = 'edit_agent?id=' + id;
			layer.open({
				type: 2,
				title: '商家编辑',
				shadeClose: true,
				shade: 0.8,
				area: ['500px', '500px'],
				content: [url]
			});
		}
		function check() {
			var agent_name = $('#agent_name').val();
			var mobile = $('#mobile').val();
			
			var ch_city = $('#ch_city').val();
			var operator = $('#operator').val();
			var order = $('#order').val();
			var cm = $('#cm').val();
			window.location.href = "/oem/accounts/agent_dcxml.html?agent_name=" + agent_name + "&mobile=" + mobile+ "&ch_city=" + ch_city+ "&operator=" + operator+ "&order=" + order+ "&cm=" + cm;
		}

	function upagent_huilv(id){
		var url='upagent_huilv?id='+id;
		layer.open({
		  type: 2,
		  title: '修改商家费率',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['500px', '	220px'],
		  content:  [url]
		}); 
	}

	function wanshan(id){
		var url='wanshan?id='+id;
		layer.open({
		  type: 2,
		  title: '完善信息',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['1200px', '900px'],
		  content:  [url]
		}); 
	}
	
	/*操作*/
	function caozuo(id,status) {
		var msg='';
		if(status==2){
			msg='冻结';
		}else{
			msg='激活';
		}
		layer.confirm('您确定要'+msg+'吗？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$.ajax({
				url: "{:url('accounts/agent_status')}",
				data: {
					id:id,
					status:status
				},
				dataType: 'json',
				success: function(data) {
					layer.msg("成功", {
						icon: 1,
						time: 1000
					}, function() {
						location.href = window.location.href;
					});
				}
			})
		})
	}
	
	/*操作*/
	function is_display(id,status) {
		var msg='';
		if(status==2){
			msg='不让该商家显示在公众号附近商家';
		}else{
			msg='在公众号附近商家显示该商家';
		}
		layer.confirm('您确定'+msg+'吗？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$.ajax({
				url: "{:url('accounts/agent_display')}",
				data: {
					id:id,
					status:status
				},
				dataType: 'json',
				success: function(data) {
					layer.msg("成功", {
						icon: 1,
						time: 2500
					}, function() {
						location.href = window.location.href;
					});
				}
			})
		})
	}
	
	function show_city_pt(agent_id){
		
		var show_url = "{:url('accounts/show_city_pt')}"+'?agent_id='+agent_id;
		
		layer.open({
			type: 2,
			title: '修改商家信息',
			shadeClose: true,
			shade: 0.8,
			area: ['460px', '260px'],
			content: show_url
		});
	}
	
	function show_score(id){
			
			var show_url = "{:url('accounts/show_score')}"+'?type=2&id='+id;
			
			layer.open({
				type: 2,
				title: '鼓励金记录',
				shadeClose: true,
				shade: 0.8,
				area: ['775px', '700px'],
				content: show_url
			});
		}
	
	function show_member(id){
			
			var show_url = "{:url('accounts/agents_tg')}"+'?id='+id;
			
			layer.open({
				type: 2,
				title: '成员列表',
				shadeClose: true,
				shade: 0.8,
				area: ['900px', '730px'],
				content: show_url
			});
		}
	
	//余额记录
	function show_charge(id){
			var show_url = "{:url('accounts/show_charge')}"+'?id='+id;
			layer.open({
				type: 2,
				title: '余额记录',
				shadeClose: true,
				shade: 0.8,
				area: ['900px', '730px'],
				content: show_url
			});
	}
	
	//商家数据统计
	function agent_count(id){
		var show_url = "{:url('accounts/agent_count')}"+'?id='+id+'&level=3';
		layer.open({
			type: 2,
			title: '商家数据统计',
			shadeClose: true,
			shade: 0.8,
			area: ['900px', '730px'],
			content: show_url
		});
	}
	
	 //编辑
	 function setagent(id){
		var url = 'edit_agent_cj?id=' + id;
		layer.open({
			type: 2,
			title: '编辑',
			shadeClose: true,
			shade: 0.8,
			area: ['600px', '480px'],
			content: [url]
		});
    }


	</script>

</html>